﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

using MapEditor.Tiles;

namespace MapEditor.Tools
{
    public abstract class Tool
    {
        //public abstract void Use(TileLayer layer, int tileX, int tileY, Rectangle selectorRect, TileType tileType, int type);
        public abstract void Use(TileLayer layer, int tileX, int tileY, TileType tileType, int type, bool showGrid);

        public abstract void DrawRegularTilePreview(SpriteBatch spriteBatch, Texture2D tilesetTexture, Rectangle previewRect);
        public abstract void DrawCustomTilePreview(SpriteBatch spriteBatch, Rectangle previewRect, TileType tileType);

        public enum PaintingType
        {
            Drawing,
            Erasing,
            None
        }

        public static Point Position = Point.Zero;
        public static PaintingType PaintType = PaintingType.None;

        public void PaintArea(TileLayer layer, int tileX, int tileY, TileType tileType, int type, bool showGrid)
        {


            /* if (showGrid)
            {
                //Rectangle tileRect = new Rectangle(selectorRect.X + (x * layer.TileSize), selectorRect.Y + (y * layer.TileSize), layer.TileSize, layer.TileSize);

                Tile replacementTile = TileFactory.Get(tileType, type, tileX, tileY);

                //bool inBounds = tileX + x >= 0 && tileY + y >= 0 && tileX + x < layer.Width && tileY + y < layer.Height;

                layer.SetTile(tileX, tileY, replacementTile);
            }
            else
            {
                NonTile replacementTile = new NonTile(type, tileX, tileY);
                layer.SetNonTiles(tileX, tileY, replacementTile);

            } */
            
            Tile replacementTile = TileFactory.Get(tileType, type, tileX, tileY, showGrid);
            layer.SetTile(tileX, tileY, replacementTile, showGrid);

            
        }

        public abstract Rectangle PreviewRect
        {
            get;
            
        }

        public abstract Rectangle PreviewRectNoGrid
        {
            get;
          
        }
    }
}
